
TO WORD WRAP THIS TEXT:

Click Edit on this screen's above toolbar and then click on Word Wrap.

TK3 TASM-MPASM CONVERSION NOTES - 22FEB03

Some of this information may update that given in the published EPE TK3 text.

Always check the Updates file for any information that affects these notes. It is normally issued whenever an update to TK3 is released and is accessible via the "Latest Updates" button at the bottom of the main TK3 screen.


The following notes are common to both Conversion routines.

TASM OBJ TO MPASM HEX

TASM OBJ (Object) files are converted to MPASM HEX files as literal translations. The OBJ codes are each held as 2-byte binary values, sequentially in the file, and are not directly readable through text editors, since any value between 0 and 255 decimal can occur. They do not hold addressing, identity or check sum values.

MPASM HEX files are formatted in what is known as the Intel style (believed to be known as INHX8M), in which address and other formatting values are included and can be read via a text editor. They are formatted so that several commands are sequenced on the same line, with the structure as for the following example (the spaces between the letter groups are omitted in actual hex files):

:NN AAAA RR MMLL MMLL MMLL MMLL CC TT

in which

":"      = record start character
"NN"     = byte quantity in line as hex value
"AAAA"   = address of first byte in hex
"RR"     = record type in hex (normally 00 except for last which is 01 - see below)
"MMLL"   = data bytes in order of MMLL in hex
"CC"     = Check Sum in hex
"TT"     = line terminator (carriage return, line feed)

Checksum is calculated as:

Sum      = byte count + address hi + address lo + record type +
           (sum of all data bytes on the line)

Checksum = (-Sum) AND 255

There can be more data values held on each line than are shown here, TK3 normally uses 16 per line when compiling hex files, in common with most assemblers.

Note that other versions of hex files exist in which the data is held in a different order. For example, whereas for MPASM the above MMLL bytes are held in order of MSB/LSB, they might be held in order of LSB/MSB in some other types of hex file. For example, whilst TASM HEX files have never been documented in EPE, the original TASM assembly software used for the EPE Simple PIC Programmer of 1996, PIC Tutorial of Mar-May 1998, and the current (as at April 2001) PICtutor CD-ROM, could be told to generate them, in which the byte order is LSB/MSB.

Only hex files in the MPASM/Intel format can be processed by TK3.

Also note that although TK3 generates the check sum when compiling hex files, it does not use the check sum when sending hex file data to the PIC - all HEX files are assumed to hold the correct data, as are all OBJ files.

It has come to light that some other record types exist (see "RR" above) - thank you originally to Malcolm Wiles. Peter Hemsley clarifies by saying that:

   00 = Data record
   01 - End of file record
   02 - Segment address record
   04 - Linear address record

and that "the last two types are concerned with 32-bit addressing and are not used in INHX8M format files". Thank you Peter!

MPASM HEX TO TASM OBJ

When converting MPASM HEX files to TASM OBJ, all address, identity and check sum data is removed, and the code data values are converted from HEX to 2-byte OBJ format.

It is important to note, however, that only HEX files for which data is omitted for the PIC's first four addresses locations (or which corresponds to the "added" programming code) can be converted to TASM OBJ. See the Assembly notes for the reason why.

When you view the OBJ data through the associated screen button, it is a decimalised version of the binary data you are examining, since binary data cannot be correctly viewed via a text editor. This decimalised data is not intended for editing or PIC programming use.

Hex files can contain embedded Config, ID and Eeprom message data which cannot be handled by an OBJ file. An intercept message advises if any are found and the conversion ends. Such data must be extracted manually from the hex file and sent to the PIC via the allocated Config and/or Send Message buttons. Refer to the above hex file structure notes for the format. ID/Config data lies between hex addresses H'4000' and H'4008' (PIC addresses H'2000' to H'2008'. Message data lies between hex addresses H'4200' (PIC H'2100') upwards, depending PIC type.

TASM ASM TO MPASM ASM

In essence there is little difference between TASM and MPASM ASM dialects. They both use the same codes as specified in Microchip's data sheets for devices such as the PIC16x84, PIC16F87x and PIC16F62x families. The principal difference is in the way that numerical values are expressed, although other minor differences exist as well. The following examples illustrate the different grammar for which TK3 translates:

	TASM		MPASM

Decimal	153		D'153'
Hex	$2B		H'2B' or 0x2B
Binary	%10010110	B'10010110'
ASCII	'C'		'C' or A'C'
Octal	-		O'777' (not recognised by TK3)

	.EQU		EQU (with/without decimal point)
	.ORG		ORG (with/without decimal point)
	.END		END (with/without decimal point)
	LABEL:		LABEL (with/without colon)

Note that TK3 does not not claim to offer full compatibility with all files created using MPASM grammar. If statements occur in files which TK3 does recognise, it is up to the user to translate the commands to a more simple form. However, we will be pleased to learn of any which are found and which you think should be included.
 
The above notes equally apply when TK3 is translating from MPASM to TASM. In the MPASM to TASM mode, though, the following additional MPASM structures are translated as well:

MPASM SHORTHAND COMMANDS

The following MPASM shorthand commands are recognised by TK3. They are not recognised by EPE TASM PIC Assemblers prior to TK3 (although EPE Toolkit Mk2 recognises them when translating from MPASM to TASM). They may not be recognised by other non-MPASM Assemblers.

MPASM COMMAND	TK3 CODING		MEANING

ADDCF f,d 	BTFSC STATUS,C		Add Carry to File
		INCF f,d

ADDDCF f,d	BTFSC STATUS,DC		Add Digit Carry to File
		INCF f,d

B k		GOTO k			Branch to

BC k		BTFSC STATUS,C		Branch on Carry to k
		GOTO k

BDC k		BTFSC STATUS,DC		Branch on Digit Carry
		GOTO k

BNC k		BTFSS STATUS,C		Branch on No Carry
		GOTO k

BNDC k		BTFSS STATUS,DC		Branch on No Digit Carry
		GOTO k

BZ k		BTFSC STATUS,Z		Branch on Zero
		GOTO k

CLRC		BCF STATUS,C		Clear Carry

CLRDC		BCF STATUS,DC		Clear Digit Carry

CLRZ		BCF STATUS,Z		Clear Zero

MOVFW,f		MOVF f,W		Move File to W

NEGF f,d	COMF f,F		Negate file
		INCF f,d

SETC		BSF STATUS,C		Set Carry

SETDC		BSF STATUS,DC		Set Digit Carry

SET Z		BSF STATUS,Z		Set Zero

SKPC		BTFSS STATUS,C		Skip on Carry

SKPDC		BTFSS STATUS,DC		Skip on Digit Carry

SKPZ		BTFSS STATUS,Z		Skip on Zero

SKPNC		BTFSC STATUS,C		Skip on No Carry

SKPNDC		BTFSC STATUS,DC		Skip on No Digit Carry

SKPNZ		BTFSC STATUS,Z		Skip on Not Zero

SUBCF f,d	BTFSC STATUS,C		Subtract Carry from File
		DECF f,d

SUBDCF f,d	BTFSC STATUS,DC		Subtract Digit Carry from File
		DECF f,d

TSTF f		MOVF f,F		Test File

Where:
d = destination (0 or 1 - W or F)
f = file
k = literal value

Note since V1.4 TK3 can also handle CBLOCK, ENDC, HIGH, LOW and DE (data) statements.

If there are other MPASM commands you feel would be useful to add to TK3's translational vocabulary, please advise.

ADDING YOUR OWN NOTES

These notes are displayed via an "Active" text editor and you may add your own notes to them, saving them to disk in the usual way.
